package com.xuxin.nantai.model;

import com.xuxin.nantai.base.BaseConstant;
import com.xuxin.nantai.base.BaseObserver;
import com.xuxin.nantai.bean.BaseBean;
import com.xuxin.nantai.bean.HangUpdateLoginBean;
import com.xuxin.nantai.bean.ProductInfoBean;
import com.xuxin.nantai.contract.HangUpdateContract;
import com.xuxin.nantai.network.RetrofitApi;
import com.xuxin.nantai.network.Retrofits;
import com.xuxin.nantai.presenter.HangUpdatePresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.schedulers.Schedulers;


/**
 * Created by xu_xin
 * Created on 2020.06.18 0018
 */
public class HangUpdateModel implements HangUpdateContract.Model {

    @Override
    public void getAllProductInfo(HangUpdatePresenter presenter,String InsType) {
        Retrofits.getInstance().createReq(RetrofitApi.class)
                .getAllProductInfo(InsType)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<ProductInfoBean>() {
            @Override
            public void onNext(ProductInfoBean bean) {
                if (BaseConstant.success_code.equals(bean.getCode())) {
                    presenter.onSuccess(bean);
                } else {
                    presenter.onError(bean);
                }
            }

            @Override
            public void onError(Throwable e) {
                presenter.onError(null);
            }

            @Override
            public void onComplete() {
                presenter.onComplete();
            }
        });
    }

    @Override
    public void update(HangUpdatePresenter presenter,
                       String LoginName,
                       String UserName,
                       String Guid,
                       String ID,
                       String cInvName,
                       String PackQty,
                       String InspectorName,
                       String InspectorCode,
                       String InspectTime,
                       String FacArea,
                       String DefectNum,
                       String DefectDes,
                       String Remark) {
        Retrofits.getInstance().createReq(RetrofitApi.class)
                .update_hang(LoginName,
                        UserName,
                        Guid,
                        ID,
                        cInvName,
                        PackQty,
                        InspectorName,
                        InspectorCode,
                        InspectTime,
                        FacArea,
                        DefectNum,
                        DefectDes,
                        Remark)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<BaseBean>() {
            @Override
            public void onNext(BaseBean bean) {
                if (BaseConstant.success_code.equals(bean.getCode())) {
                    presenter.onSuccess(bean);
                } else {
                    presenter.onError(bean);
                }
            }

            @Override
            public void onError(Throwable e) {
                presenter.onError(null);
            }

            @Override
            public void onComplete() {
                presenter.onComplete();
            }
        });
    }
}